package View

import ControllerView.ControllerView
import com.trolltech.qt.gui._
import FilesGenerator.UserConfig
import ControllerView.ControllerToolsView
import com.trolltech.qt.core.QRect

/**
 * Created by IntelliJ IDEA.
 * User: danymorard
 * Date: 13.04.11
 * Time: 17:07
 * To change this template use File | Settings | File Templates.
 */

class ImportSoftView(controller: ControllerView, parent: QWidget) extends View(controller, parent) {

  /**
   * Label position in the container
   */
  protected val GEOMETRY_LABEL = new QRect(5,5,130,25)

  /**
   * Line position in the container
   */
  protected val GEOMETRY_LINE = new QRect(140,5,390,25)

  /**
   * Button position in the container
   */
  protected val GEOMETRY_BUTTON = new QRect(140,35,80,25)

  // Container for the path of scala
  protected var containerScala = new QWidget(container)
  protected var containerSDK   = new QWidget(container)
  protected var containerProguard = new QWidget (container)

  // browse button
  protected var buttonPathScala = new QPushButton(containerScala)
  protected var buttonPathsdk = new QPushButton(containerSDK)
  protected var buttonPathProguard = new QPushButton(containerProguard)

  // label
  protected var labelScala = new QLabel(containerScala)
  protected var labelsdk = new QLabel(containerSDK)
  protected var labelProguard = new QLabel(containerProguard)

  // line edit
  var lineEditScala = new QLineEdit(containerScala)
  var lineEditsdk = new QLineEdit(containerSDK)
  var lineEditProguard = new QLineEdit(containerProguard)

 // protected var gridVLayout = new QVBoxLayout(container)

  // init View
  this.initView

  /**
   * Initialize the view
   */
  private def initView {



    // size of the view
    if (controller.isInstanceOf[ControllerToolsView]){

      // this view is displayed in the tools window
        this.setGeometry(TOOLS_VIEW_SIZE)
    }else{

      // this view is displayed in the create project view
        this.setGeometry(OPTION_VIEW_SIZE)
    }

    // create container for scala path
    containerScala.setGeometry(5,50,600,100)
    labelScala.setGeometry(GEOMETRY_LABEL)
    lineEditScala.setGeometry(GEOMETRY_LINE)
    buttonPathScala.setGeometry(GEOMETRY_BUTTON)


    containerSDK.setGeometry(5,160,600,100)
    labelsdk.setGeometry(GEOMETRY_LABEL)
    lineEditsdk.setGeometry(GEOMETRY_LINE)
    buttonPathsdk.setGeometry(GEOMETRY_BUTTON)


    containerProguard.setGeometry(5,270,600,100)
    labelProguard.setGeometry(GEOMETRY_LABEL)
    lineEditProguard.setGeometry(GEOMETRY_LINE)
    buttonPathProguard.setGeometry(GEOMETRY_BUTTON)



    // set the text
    labelScala.setText("Scala framework")
    labelsdk.setText("Android SDK")
    labelProguard.setText("Proguard")


    // edit the button browse
    buttonPathScala.setText("Browse")
    buttonPathsdk.setText("Browse")
    buttonPathProguard.setText("Browse")

    // connection
    buttonPathScala.clicked.connect(this, "browseScala()")
    buttonPathsdk.clicked.connect(this, "browseSdk()")
    buttonPathProguard.clicked.connect(this, "browseProguard()")


    // set name
     buttonPathScala.setObjectName(CSS_BROWSE_BUTTON)
    buttonPathsdk.setObjectName(CSS_BROWSE_BUTTON)
    buttonPathProguard.setObjectName(CSS_BROWSE_BUTTON)


    // set size button
    buttonPathScala.setFixedSize(SIZE_BUTTON_BROWSE)
    buttonPathsdk.setFixedSize(SIZE_BUTTON_BROWSE)
    buttonPathProguard.setFixedSize(SIZE_BUTTON_BROWSE)

    // create the grid layout
    //gridVLayout.addWidget(containerScala)
    //gridVLayout.addWidget(containerSDK)
    //gridVLayout.addWidget(containerProguard)

  }

  /**
   * Clear all text field
   */
  def eraseTextField{

    lineEditsdk.clear
    lineEditProguard.clear
    lineEditScala.clear
  }

  def saveEntries {
    //save entries of first window
    UserConfig.scalaPath = lineEditScala.text
    UserConfig.androidSdkPath = lineEditsdk.text
    UserConfig.proguardPath = lineEditProguard.text
    UserConfig.save
  }

  def browseScala() {
    lineEditScala.setText(QFileDialog.getExistingDirectory(new QWidget, new String("Open Directory")))
    UserConfig scalaPath = lineEditScala.text
    UserConfig save

  }

  def browseSdk() {
    lineEditsdk.setText(QFileDialog.getExistingDirectory(new QWidget, new String("Open Directory")))
    UserConfig androidSdkPath = lineEditsdk.text
    UserConfig save
  }

  def browseProguard() {
    lineEditProguard.setText(QFileDialog.getExistingDirectory(new QWidget, new String("Open Directory")))
    UserConfig proguardPath = lineEditProguard.text
    UserConfig save
  }

}